HTTP_PUT Function
Syntax
Arguments
- urlCharacter
The address of the server that will receive your data.
- bodyCharacter
The parameters you wish to send. The size of this field is unlimited.
- cookieCharacter
Default = "". Cookie data.
- portNumeric
Default = 80. The port to use.
- timeoutNumeric
Default = 8000 milliseconds. The number of milliseconds to wait before timing out.
- show_before_sendLogical
Default = .F.. When .T., displays the request before being sent. Useful for debugging.
- validate_ssl_certLogical
Default = .T.. If the specified URL starts with "https://", this flag controls whether or not the certificate offered by the server will be validated.
- SSLCipherListCharacter
SSL Cipher List
Returns
- ResultPointer
A dot variable containing the server's response.
- error_textCharacter
The error message, if any. If no error occurs, error_text will be empty.
- error_codeNumeric
The error number, if any. If no error occurs, error_code will be 0.
- headersCharacter
Response headers. If error_code is 0, the result will contain a dot variable, parsed_headers, with a property representing each response header.
- bodyCharacter
Response body.
- parsed_headersPointer
Contains all the headers in the response split out into individual properties. If an error occurred when trying to communicate with the server, parsed_headers will be empty. parsed_headers will always contain the following properties in addition to the headers in the response:
- http_versionCharacter
The HTTP version used.
- reason_phraseCharacter
A description of the status code.
- status_codeNumeric
The response status code. See Status Codes for a list of status codes.
Description
Use the HTTP method PUT to retrieve the specified URL
Discussion
The HTTP_PUT() function requests a URL using the PUT method with TLS 1.2 or newer. The function returns a pointer with the parsed response from the server. If error_code is "0", parsed_response will contain the headers in the result:
? result.parsed_headers = AccessControlAllowCredentials = "true" AccessControlAllowOrigin = "*" Connection = "close" ContentLength = "390" ContentType = "application/json" Date = "Tue, 13 Jul 2021 18:07:33 GMT" http_version = "HTTP/1.1" reason_phrase = "OK" Server = "gunicorn/19.9.0" status_code = 200
Status code 200 indicates that the page exists. Status code 404 indicates that it does not. Other status codes you may encounter, along with the meanings of each, are documented in Status Codes.
Handling Redirects
When the server responds with a 30* code, HTTP_PUT() does not automatically use the new URL. The developer needs to examine result.parsed_headers.status_code, then if appropriate, try the URL provided in result.parsed_headers.location. Refer to HTTP_GET() for an example.
Example
dim result as p result = http_put("https://httpbin.org/put") ? result.error_code = 0 ? result.parsed_headers = AccessControlAllowCredentials = "true" AccessControlAllowOrigin = "*" Connection = "close" ContentLength = "390" ContentType = "application/json" Date = "Tue, 13 Jul 2021 18:07:33 GMT" http_version = "HTTP/1.1" reason_phrase = "OK" Server = "gunicorn/19.9.0" status_code = 200 a5_show_html(result.body)
See Also